import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class useCallable {
    //Runnable
//    private static int sum = 0;
//    public static void main(String[] args) throws InterruptedException {
//        Thread t = new Thread( () -> {
//            int result = 0;
//            for (int i = 0; i <= 1000; i++) {
//               result += i;
//            }
//            sum = result;
//        });
//        t.start();
//        t.join();
//        System.out.println(sum);
//    }
  //Callable
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int result = 0;
                for (int i = 0; i <= 1000; i++) {
                    result += i;
                }
                return result;
            }
        };
            FutureTask futureTask = new FutureTask<>(callable);//小票（号码牌）
            Thread t = new Thread(futureTask);
            t.start();
            t.join();
        System.out.println(futureTask.get());
        }
}
